package com.weigee.ktv.view.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.bumptech.glide.Glide
import com.weigee.ktv.R
import com.weigee.ktv.model.enums.ImagePreLoad
import com.weigee.ktv.model.enums.WeigeeHost
import kotlinx.android.synthetic.main.item_wallet_safety_settings.view.*

/**
 * Created by linde on 2017/6/16.
 * <p/>
 */
class WalletSafetyItemView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr)
{
    var textLeft: String? = null
        set(value)
        {
            item_wallet_safety_tv_left?.let {
                it.text = value
                field = value
            }
        }

    var textRight: String? = null
        set(value)
        {
            item_wallet_safety_tv_right?.let {
                it.text = value
                field = value
            }
        }

    init
    {
        LayoutInflater.from(context).inflate(R.layout.item_wallet_safety_settings, this, true)
        Glide.with(context).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(item_wallet_safety_iv_right)
        attrs?.let {
            val ta = context.obtainStyledAttributes(it, R.styleable.WalletSafetyItemView)

            textLeft = ta.getString(R.styleable.WalletSafetyItemView_wallet_safety_item_text_left)
            textRight = ta.getString(R.styleable.WalletSafetyItemView_wallet_safety_item_text_right)

            ta.recycle()
        } ?: let {
            textLeft = ""
            textRight = ""
        }
    }
}